package com.system.provider;

import com.am.ui.grid.AbstractBaseGridProvider;
import com.system.uitls.CommonUtil;
import com.system.uitls.SearchFilter;
import java.util.Map;

public class DrugListProvider extends AbstractBaseGridProvider
{
  public String generateSql(Map<String, Object> map)
  {
    String value = CommonUtil.nullToEmptyString(map.get("value"));
    String low = CommonUtil.nullToEmptyString(map.get("low"));
    String campus = CommonUtil.nullToEmptyString(map.get("campus"));
    StringBuffer sql = null;
    if ((value != "") && (Integer.parseInt(value) == 1)) {
      if ((Integer.parseInt(low) == 2) || (Integer.parseInt(low) == 0))
        sql = new StringBuffer("SELECT id,name,vender,spec,unit,batch_number_valid,supply_price,(supply_price*storeroom_num) AS total,storeroom_num AS drug_num FROM sys_drug WHERE storeroom = " + campus);
      else {
        sql = new StringBuffer("SELECT id,name,vender,spec,unit,batch_number_valid,supply_price,(supply_price*storeroom_num) AS total,storeroom_num AS drug_num FROM sys_drug WHERE storeroom_min >= storeroom_num AND storeroom = " + campus);
      }
    }
    else if ((Integer.parseInt(low) == 2) || (Integer.parseInt(low) == 0))
      sql = new StringBuffer("SELECT id,name,vender,spec,unit,batch_number_valid,supply_price,(supply_price*drugstore_num) AS total,drugstore_num AS drug_num FROM sys_drug WHERE storeroom = " + campus);
    else {
      sql = new StringBuffer("SELECT id,name,vender,spec,unit,batch_number_valid,supply_price,(supply_price*drugstore_num) AS total,drugstore_num AS drug_num FROM sys_drug WHERE drugstore_min >= drugstore_num AND storeroom = " + campus);
    }

    sql.append(SearchFilter.getSearchSql(map, null));
    setParamMap(map);
    return sql.toString();
  }
}